package com.quanxiaoha.ai.robot.config;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Caius
 * @description
 * @since Created in 2025-09-04
 */
@Configuration
public class ChatClientConfig {

    @Resource
    private ChatMemory chatMemory;

    /**
     * 初始化 ChatClient 客户端
     * @param chatModel
     * @return
     */
    @Bean
    public ChatClient chatClient(DeepSeekChatModel chatModel) {
        return ChatClient.builder(chatModel)
                .defaultAdvisors(new SimpleLoggerAdvisor(), //Spring-ai 内置的 advisor 处理器
//                                 new MyLoggerAdvisor(),   // 自定义日志 advisor 处理器打印
                        MessageChatMemoryAdvisor.builder(chatMemory).build()
                        )
//                .defaultSystem("请你扮演 caius 希望找到 java 实习工作的 java 练习生")
                .build();
    }
}
